package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.BaseTrademark;
import com.atguigu.gmall.product.service.BaseTrademarkService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/product/baseTrademark")
public class BaseTrademarkController {

    private BaseTrademarkService baseTrademarkService;

    @Autowired
    public BaseTrademarkController(BaseTrademarkService baseTrademarkService) {
        this.baseTrademarkService = baseTrademarkService;
    }

    @GetMapping("/{page}/{size}")
    public Result<IPage<BaseTrademark>> getBaseTrademarkPage(@PathVariable Long page, @PathVariable Long size) {
        Page<BaseTrademark> baseTrademarkPage = new Page<>(page, size);
        IPage<BaseTrademark> spuInfoPageList = this.baseTrademarkService.getBaseTrademarkPage(baseTrademarkPage);
        return Result.ok(spuInfoPageList);
    }

    @PostMapping("/save")
    public Result save(@RequestBody BaseTrademark baseTrademark) {
        this.baseTrademarkService.save(baseTrademark);
        return Result.ok();
    }

    @PutMapping("/update")
    public Result update(@RequestBody BaseTrademark baseTrademark) {
        this.baseTrademarkService.updateById(baseTrademark);
        return Result.ok();
    }

    @GetMapping("/get/{id}")
    public Result getById(@PathVariable Long id) {
        BaseTrademark baseTrademark = this.baseTrademarkService.getById(id);
        return Result.ok(baseTrademark);
    }

    @DeleteMapping("/remove/{id}")
    public Result remove(@PathVariable Long id) {
        this.baseTrademarkService.removeById(id);
        return Result.ok();
    }

}
